/*
 * eeprom_test.c
 *
 * Created: 13/02/2012 11:12:04
 *  Author: Dani
 */ 

#include <avr/io.h>
#define F_CPU 3686400
#include <avr/delay.h>
#include "led.h"
#include "switch.h"
#include <avr/eeprom.h>

/*
void EEPROM_write(unsigned int uiAddress, unsigned char ucData) // from mega32 data sheet
{
	// Wait for completion of previous write 
	while(EECR & (1<<EEWE))	;
	// Set up address and data registers
	EEAR = uiAddress;
	EEDR = ucData;
	// Write logical one to EEMWE
	EECR |= (1<<EEMWE);
	//EECR = 0b00000100;
	// Start eeprom write by setting EEWE 
	EECR |= (1<<EEWE);
}

unsigned char EEPROM_read(unsigned int uiAddress) // from mega32 data sheet
{
	// Wait for completion of previous write 
	while(EECR & (1<<EEWE));
	
	// Set up address register 
	EEAR = uiAddress;
	// Start eeprom read by writing EERE 
	EECR |= (1<<EERE);
	// Return data from data register
	return EEDR;
}*/

int main(void)
{
    unsigned char a;
	initLEDport();
	writeAllLEDs(0b00110011);
	//_delay_ms(1000);
	        
	while(1)
    {
		_delay_ms(1000);
		eeprom_busy_wait();
		eeprom_write_byte(1,0b11001100);
		a = eeprom_read_byte(1);
		writeAllLEDs(a);
		//_delay_ms(1000);	
    }
}

